<?php
namespace Home\Controller;

use Think\Controller;

class LoginController extends Controller
{
    public function index()
    {

        $question=D('Verify')->getoneverify();
        $this->assign('question',$question);
        $this->display();
    }

    public function checkdata(){
        // {"email":"fsdf@df.com","username":"dsf","pass":"dsfsdf","repass":"dsfsdf","vercode":"dsfdsf"}
        $pass=I('post.pass');  //用户传过来的密码
        $email=I('post.email');//用户传古来的邮箱
        $name=I('post.username');
        $answer=$_SESSION['answer'];//拿到了这个习近平答案
        $panswer=I('post.vercode');//人类验证
        $e=D('User')->checkEmail($email)?false:true;
        $passu=D('User')->checkpass($email);

//        var_dump($answer." ".$panswer);
        if($answer != $panswer){
            $arr=array(
                "error"=>1,
                "info"=>"验证码错误啦！"
            );
            echo json_encode($arr);
            exit();
        }

        if($e){
            $arr=array(  //44092119920715217X
                "error"=>1,
                "info"=>"该邮箱还没注册！"
            );
            echo json_encode($arr);
            exit();

        }

        if(md5($pass)!=$passu){
            $arr=array(
                "error"=>1,
                "info"=>"密码错误！"
            );
            echo json_encode($arr);
            exit();
        }


        if( true){
            $arr=array(
                "error"=>0,
                "info"=>"登录成功"
            );
            $_SESSION['nickname']=D('User')->getnickname($email)['nickname'];
            $_SESSION['id']=D('User')->getnickname($email)['id'];
            $_SESSION['face']=D('User')->getnickname($email)['face'];
            echo json_encode($arr);

//            var_dump(D('User')->getnickname($email));
            exit();
        }else{
            $arr=array(
                "error"=>1,
                "info"=>"登录失败啦！"
            );
            echo json_encode($arr);
            exit();
        }


    }







}